<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2025/4/29
  Time: 9:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加人员</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
        }

        form {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
        }

        .form-group {
            margin-bottom: 15px;
            display: flex;
            align-items: center;
        }

        .form-group label {
            width: 100px;
            margin-right: 10px;
        }

        .form-group input,
        .form-group select {
            padding: 5px;
            border: 1px solid #ccc;
            border-radius: 3px;
            flex: 1;
        }

        .required {
            color: red;
            margin-left: 5px;
        }
    </style>
</head>
<body>
<form id="addPersonForm">
    <h3 style="text-align: center; color: red;">添加人员</h3>
    <div class="form-group">
        <label for="name">姓名：</label>
        <input type="text" id="name" name="name" required>
        <span class="required">*</span>
    </div>
    <div class="form-group">
        <label for="gender">性别：</label>
        <select id="gender" name="gender" required>
            <option value="">请选择</option>
            <option value="男">男</option>
            <option value="女">女</option>
        </select>
        <span class="required">*</span>
    </div>
    <div class="form-group">
        <label for="age">年龄：</label>
        <input type="number" id="age" name="age" required>
        <span class="required">*</span>
    </div>
    <div class="form-group">
        <label for="level">等级：</label>
        <select id="level" name="level" required>
            <option value="">请选择</option>
            <option value="初级">初级</option>
            <option value="中级">中级</option>
            <option value="高级">高级</option>
        </select>
        <span class="required">*</span>
    </div>
    <div class="form-group">
        <label for="department">部门：</label>
        <select id="department" name="department">
            <option value="">请选择</option>
            <option value="研发部">研发部</option>
            <option value="市场部">市场部</option>
            <option value="财务部">财务部</option>
        </select>
        <span class="required">*</span>
    </div>
    <div class="form-group">
        <input type="button" value="提交" onclick="submitForm()">
    </div>
</form>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    function submitForm() {
        const formData = $('#addPersonForm').serialize();
        
        $.ajax({
            url: '<%=request.getContextPath()%>/personController?op=add',
            type: 'POST',
            data: formData,
            success: function(response) {
                alert('提交成功');
                window.location.href = '<%=request.getContextPath()%>/personController?op=members';
                // 可根据后台返回的response做进一步处理
                // 例如跳转页面: window.location.href = 'success.jsp';
            },
            error: function(xhr, status, error) {
                alert('提交失败: ' + error);
            }
        });
    }
</script>
</body>
</html>